package com.google.appengine;

import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

public class DevAppServerPreferences implements AutoCloseable {

  private static final String PORT = "port";
  private Preferences prefs;
  
  public DevAppServerPreferences() {
    this.prefs = Preferences.userNodeForPackage(DevAppServerClient.class);
  }
  
  public boolean prefsExist() {
    try {
      return prefs.nodeExists(PORT);
    } catch (BackingStoreException e) {
      return false;
    }
  }
  
  public int getPort() {
    return prefs.getInt(PORT, -1);
  }
  
  public void setPort(int port) {
    prefs.putInt(PORT, port);
  }
  
  public void clear() {
    try {
      prefs.clear();
    } catch (BackingStoreException e) {
    }
  }

  @Override
  public void close() {
    this.prefs = null;
  }
  
}
